﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcCms.Web.ViewModels.BackOfficeModel>" %>

<asp:Content ID="Content5" ContentPlaceHolderID="TitleContent" runat="server">
    <%=ViewData["PageTitle"]%>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
    <style type="text/css">
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="content-container-inner">
    <h2>
        <%=ViewData["PageTitle"]%></h2>    
    <div class="thecontent">
        <div>To Add A New Redirect Navigate To The URL whose content is not there and then return to this page and the old url will be inserted for you to edit.</div>
        <br />
        <table class="redirectTable" cellpadding="3" width="100%" cellspacing="0" border="1" style="background-color:White">
            <tr>
                <th>
                    Description
                </th>
                <th width="100px">
                    Old URL
                </th>
                <th>
                    New URL
                </th>
                <th>
                    Is File                   
                </th>
                <th>
                    &nbsp;
                </th>
            </tr>
            <%
                foreach (var redirect in Model._Redirects)
                {
   
            %>
            <tr>
                <td>
                    <%=Html.TextBox("Description-"+redirect.Redirect301ID.ToString(), redirect.Description)%>
                </td>
                <td>
                    <input type="text" value="<%=redirect.OldPage%>" />
                </td>               
                <td>                    
                    <%=Html.TextBox("NewURL-"+redirect.Redirect301ID.ToString(), redirect.NewPage, new {@class="redirectTableNewUrl"})%>
                </td>
                <td>
                    <%=Html.CheckBox("IsFile"+redirect.Redirect301ID.ToString(), redirect.IsFile) %>
                </td>
                <td><a onclick="SaveRedirect('<%=redirect.Redirect301ID.ToString() %>');" href="javascript:void(0);">
                        <img alt="save" class="saveIcon" title='Save Changes' src='/content/images/save.gif'  />                                          
                    </a>
                    <img id="greenCheck-<%=redirect.Redirect301ID.ToString() %>" alt="saved" src="/content/images/greencheck.gif" style="display:none" />
                    <%=Html.Hidden("OldURL-" + redirect.Redirect301ID.ToString(), redirect.OldPage)%>
                </td>
            </tr>
            <%
                }    
            %>
        </table>
    </div>
</div>    
</asp:Content>
<asp:Content ID="SidebarContent" ContentPlaceHolderID="SidebarContent" runat="server">

</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
    <script language="javascript" type="text/javascript">

        function SaveRedirect(redirectId) {
            $('#greenCheck-' + redirectId).hide();
            $.post(
            "/backOfficeAjax/saveRedirect/" + redirectId,
            {
                newPage: $('#NewURL-' + redirectId).val(),
                description: $('#Description-' + redirectId).val(),
                redirect301ID: redirectId,
                oldPage: $('#OldURL-' + redirectId).val(),
                isFile: $('#IsFile-' + redirectId).is(':checked')
            },
            function (data) {
                //var objdata = JSON.parse(data);
                var objdata = data;
                if (objdata.error) {
                    alert(objdata.error);
                }
                else {
                    if (objdata.result == "success") {
                        $('#greenCheck-' + redirectId).show();
                    }
                    else {
                        alert("There was a problem saving the redirect.");
                    }
                }
            },
            "json"
            );
        }      
    </script>
</asp:Content>
